package com.caisejingyu.whales.home.ui

import android.app.Activity
import android.graphics.Bitmap
import android.os.Bundle
import android.view.View

import com.caisejingyu.whales.home.R
import com.caisejingyu.whales.home.devices.camera.CameraListener
import com.caisejingyu.whales.home.devices.camera.CameraServiceImpl
import com.caisejingyu.whales.home.devices.camera.ICameraManage
import kotlinx.android.synthetic.main.test_activity_camera.*


class CameraTestActivity : Activity() {
    var cameraManage: ICameraManage? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.test_activity_camera)
        cameraManage = CameraServiceImpl().cameraManage(this, surface_view_camera2_activity)

        findViewById<View>(R.id.start).setOnClickListener { cameraManage?.restart() }
        findViewById<View>(R.id.stop).setOnClickListener { cameraManage?.pause() }
        findViewById<View>(R.id.close).setOnClickListener { cameraManage?.destroy() }
        findViewById<View>(R.id.takePicture).setOnClickListener { cameraManage?.takePicture() }
        findViewById<View>(R.id.hidden).setOnClickListener { iv_show_camera2_activity.visibility = View.GONE }

        cameraManage?.setCameraListener(object : CameraListener {
            override fun cameraCallback(bitmap: Bitmap) {
                iv_show_camera2_activity.visibility = View.VISIBLE
                iv_show_camera2_activity.setImageBitmap(bitmap)
            }
        })
    }
}
